﻿using Grow.Module.Thread;

namespace Grow.Module.Service
{
    /// <summary>
    /// 服务提供上下文
    /// </summary>
    public interface IServiceContext
    {

        /// <summary>
        /// 获取请求服务
        /// </summary>
        /// <typeparam name="T">服务类型</typeparam>
        TService GetRequiredService<TService>() where TService : notnull;

        /// <summary>
        /// 获取请求服务
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        object GetRequiredService(Type serviceType);

        /// <summary>
        /// 获取请求服务
        /// </summary>
        /// <typeparam name="T">服务类型</typeparam>
        TService? GetService<TService>() where TService : notnull;

        /// <summary>
        /// 获取请求服务
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        object? GetService(Type serviceType);

        /// <summary>
        /// 获取请求服务
        /// </summary>
        /// <typeparam name="T">服务类型</typeparam>
        IEnumerable<TService> GetServices<TService>() where TService : notnull;

        /// <summary>
        /// 获取请求服务
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        IEnumerable<object?> GetServices(Type serviceType);
        /// <summary>
        /// 获取选项
        /// </summary>
        /// <typeparam name="TOptions"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        TOptions GetOptions<TOptions>(string? key = null) where TOptions : class;

        /// <summary>
        /// 服务提供上下文
        /// </summary>
        /// <returns></returns>
        IServiceContext GetServiceContext();

        /// <summary>
        /// 异步任务取消令牌提供程序
        /// </summary>
        /// <returns></returns>
        ICancellationTokenContext GetCancellationTokenContext();
    }
}
